<?php
namespace Admin\Controller;
use Admin\Controller\ApplyController;
use Admin\Controller\MatApplyController;
class CheckController extends AdminController{
//审核管理
    protected function _initialize() {
    parent::_initialize ();
  }
  //审核未完成
  public function not_index()
  {
    $where = '1 = 1';
    if(I('get.aid', -1, 'intval') <> -1)
    {
      if(I('get.aid', -1, 'intval')==0)
      {
        $where .=' and  aid =0';
      }else{
        $where .=' and aid='.I('get.aid', 0, 'intval');
      }
    }
    $where .= I('get.user_name') != '' ? ' and user_name like "%'.I('get.user_name').'%"' : '';

    $where .= I('get.telephone') != '' ? ' and telephone = '.I('get.telephone') : '';

    $where .= I('get.create_time_beg') != '' ? ' and create_time >= '.strtotime(I('get.create_time_beg')) : '';

    $where .= I('get.create_time_end') != '' ? ' and create_time < '.strtotime(I('get.create_time_end')) : '';

    $where .= I('get.status') !='' ? ' and status='.I('get.status') : ' and u.status = 101';
    if(session('adminInfo.gpid')!=0)
    {
        $groupInfo=$this->getInfo('*','group','id='.session('adminInfo.gpid'));
        if($groupInfo['work_status']==1)
        {
           $where.=' and gpid='.session('adminInfo.gpid');
        }
    }

    if($_GET['check_status']!='')
    {
       $where.=' and check_status='.$_GET['check_status'];
    }
    $where.=' and check_admin_id='.session('adminInfo.id');
    $list=$this->getList('u.*,b.bank_short_name','user u',$where,'u.id desc',true,'left join app_bank b on u.loan_bank_id=b.id');
    foreach ($list as $key => $value) {
      $group=$this->getInfo('*','group','id='.$value['gpid']);
      $list[$key]['group_name']=$group['name'];
    }
    $this->assign('list', $list);
    $this->display();
  }
//根据审核状态查询列表
  public function getCheck_status($check_status=0,$status=null)
  {
         $where = '1 = 1';
    if(I('get.aid', -1, 'intval') <> -1)
    {
      if(I('get.aid', -1, 'intval')==0)
      {
        $where .=' and  aid =0';
      }else{
        $where .=' and aid='.I('get.aid', 0, 'intval');
      }
    }
    $where .= I('get.user_name') != '' ? ' and u.user_name like "%'.I('get.user_name').'%"' : '';
    $where .= I('get.identity_no') != '' ? ' and u.identity_no like "%'.I('get.identity_no').'%"' : '';
    $where .= I('get.department_name') != '' ? ' and u,department_name like "%'.I('get.department_name').'%"' : '';

    $where .= I('get.telephone') != '' ? ' and u.telephone = '.I('get.telephone') : '';

    $where .= I('get.create_time_beg') != '' ? ' and u.create_time >= '.strtotime(I('get.create_time_beg')) : '';

    $where .= I('get.create_time_end') != '' ? ' and u.create_time < '.strtotime(I('get.create_time_end')) : '';

    $where .= I('get.status') !='' ? ' and u.status='.I('get.status') : ' and ( u.status'.$status .' or u.status = 9 )' ;
    $groupInfo=$this->getInfo('*','group','id='.session('adminInfo.gpid'));
    if($groupInfo['work_status']==1)
    {
       $where.=' and gpid='.session('adminInfo.gpid');
    }
      if(session('adminInfo.gid')==1){
          $where.=' and check_status='.$check_status;
      }
      else if($check_status==3)
    {
      $where.=' and check_status='.$check_status.' and check_admin_id='.session('adminInfo.id');
    }else{
      $where.=' and check_status='.$check_status;
    }
//      print_r($where);die;

    $list = $this->getList('u.*,b.bank_short_name','user u',$where,'u.id desc',true,' join app_bank b on b.id = u.loan_bank_id');
    // echo M()->getLastsql();
    // exit;
    foreach ($list as $key => $value) {
      $group=$this->getInfo('*','group','id='.$value['gpid']);
      $list[$key]['group_name']=$group['name'];
    }
    return $list;
  }
  //区域经理审核列表
  public function Region_manager()
  {
    $list=$this->getCheck_status(1,'=1');
    $this->assign('list', $list);
    $this->display();
  }
//区域经理审核
  public function Region_check()
  {
      $id=I('get.user_id',0,'intval');
      $check_log=$this->getList('*','check_log','check_status >= 1 and check_status <= 2 and user_id='.$id,'id asc');
      $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

      $src =[];

      $pics = '';
      foreach($userFiles as $k3)
      {
        $dist  = $k3['file_dist'];
        $src[] = $dist;

        $_files = explode(',', $k3['file_dist']);
        if (count($_files) <= 1 && end(explode('.', $k3['file_dist'])) != 'mp4')
        {
          $pics.= "'".$k3['file_dist']."',";
        }

      }

      $this->assign('src',$pics);
      $this->assign('check_log',$check_log);
      $this->assign('userFiles',$userFiles);
      $detail=new ApplyController();
      $detail->get_info($id);
      $this->display();
  }
  //审核助理(审核列表)
  public function assistant()
  {
    $list=$this->getCheck_status(2,'=1');
    $this->assign('list', $list);
    $this->display();


  }
//审核助理审核
  public function assistant_check()
  {

      $id=I('get.user_id',0,'intval');
      $detail=new ApplyController();
      $detail->get_info($id);
      $check_log=$this->getList('*','check_log','user_id='.$id.' and check_status >= 1 and check_status <= 3','id asc');
      $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

      $src =[];

      $pics = '';
      foreach($userFiles as $k3)
      {
        $dist  = $k3['file_dist'];
        $src[] = $dist;

        $_files = explode(',', $k3['file_dist']);
        if (count($_files) <= 1 && end(explode('.', $k3['file_dist'])) != 'mp4')
        {
          $pics.= "'".$k3['file_dist']."',";
        }

      }

      $this->assign('src',$pics);
      $this->assign('check_log',$check_log);
      $this->assign('userFiles',$userFiles);
      $this->display();
  }
  //初审列表
 public function frist()
 {
   $list=$this->getCheck_status(3,'=1');
    $this->assign('list', $list);
    $this->display();
 }

 //初审审核
 public function frist_check()
 {

      $id=I('get.user_id',0,'intval');
      $detail=new ApplyController();
      $detail->get_info($id);
      $check_log=$this->getList('*','check_log','user_id='.$id.' and check_status >= 1 and check_status <= 4','id asc');
      $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

      $src =[];

      $pics = '';
      foreach($userFiles as $k3)
      {
        $dist  = $k3['file_dist'];
        $src[] = $dist;

        $_files = explode(',', $k3['file_dist']);
        if (count($_files) <= 1 && end(explode('.', $k3['file_dist'])) != 'mp4')
        {
          $pics.= "'".$k3['file_dist']."',";
        }


      }

      $this->assign('src',$pics);
      $this->assign('userFiles',$userFiles);
      $this->assign('check_log',$check_log);
      $this->display();

 }
 //审核主管（审核列表）
 public function admin()
 {
    $list=$this->getCheck_status(4,'=1');
    $this->assign('list', $list);
    $this->display();
 }
//审核主管审核
 public function admin_check()
 {
      $id=I('get.user_id',0,'intval');
      $detail=new ApplyController();
      $detail->get_info($id);
      $check_log=$this->getList('*','check_log','user_id='.$id.' and check_status >= 1 and check_status <= 5','id asc');
      $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

      $src =[];

      $pics = '';
      foreach($userFiles as $k3)
      {
        $dist  = $k3['file_dist'];
        $src[] = $dist;

        $_files = explode(',', $k3['file_dist']);
        if (count($_files) <= 1 && end(explode('.', $k3['file_dist'])) != 'mp4')
        {
          $pics.= "'".$k3['file_dist']."',";
        }

      }

      $this->assign('src',$pics);
      $this->assign('check_log',$check_log);
      $this->assign('userFiles',$userFiles);
      $this->display();

 }
   //审核经理(审核列表)
  public function manager()
  {
    $list=$this->getCheck_status(5,'=1');
    $this->assign('list', $list);
    $this->display();
  }
//审核经理审核
  public function manager_check()
  {

      $id=I('get.user_id',0,'intval');
      $detail=new ApplyController();
      $detail->get_info($id);
      $check_log=$this->getList('*','check_log','user_id='.$id.' and check_status >= 1 and check_status <= 6','id asc');
      $userFiles = $this->getList('*','user_file','user_id = '.$id.' and status=0','id desc');

      $src =[];

      $pics = '';
      foreach($userFiles as $k3)
      {
        $dist  = $k3['file_dist'];
        $src[] = $dist;

        $_files = explode(',', $k3['file_dist']);
        if (count($_files) <= 1 && end(explode('.', $k3['file_dist'])) != 'mp4')
        {
          $pics.= "'".$k3['file_dist']."',";
        }

      }

      $this->assign('src',$pics);
      $this->assign('check_log',$check_log);
      $this->assign('userFiles',$userFiles);
      $this->display();


  }

  public function add_CheckInfo()
  {
    // <option value="1">通过</option>
    // <option value="11">待定</option>
    // <option value="12">退回</option>
    // <option value="0">拒贷</option>
      $admin_id=session('adminInfo.id');
      $info=$this->getInfo('a.*,g.name as group_name',array('admins a','group g'),'a.gid=g.id and a.id='.$admin_id);
      $type=$info['group_name'];
      $check_status=$_POST['check_status'];

      $check_exist=$this->find_status($_POST['user_id'],$check_status);
      if($check_exist)
      {
        $this->error('该申请已审核，不能重复');
      }
      $data=array(
               'user_id'=>$_POST['user_id'],//申请  人id
               'admin_id'=>$admin_id,//审核人id
               'admin_name'=>$info['name'],//审核人
               'type'=>$type,//身份类型
               'status'=>$_POST['Cstatus'],//审核：1通过，0不通过
               'note'=>$_POST['note'],//备注
               'opinion'=>$_POST['opinion'],//审核意见
               'refuse_type'=>implode(',',$_POST['reType']),

               'ability'=>$_POST['ability'],//还款能力分析
               'desire'=>$_POST['desire'],//还款意愿分析
               'gaowei_user'=>$_POST['gaowei_user'],//是否为高危用户
               'key'=>$_POST['key'],//是否留有钥匙
               'gaowei_content'=>$_POST['gaowei_content'],//高危情况描述

               'add_time'=>time(),
               'check_status'=>$check_status
        );

      $result=M('check_log')->add($data);
      switch ($check_status) {
        case '1':
           $rec_url='/Admin/Inside/check';
           $url='Inside/check';
          break;
        case '2':
           $rec_url='/Admin/Check/Region_manager';
           $url='Check/Region_manager';
          break;
        case '3':
           $rec_url='/Admin/Check/assistant';
           $url='Check/assistant';
          break;
        case '4':
           $rec_url='/Admin/Check/frist';
           $url='Check/frist';
          break;
        case '5':
           $rec_url='/Admin/Check/admin';
           $url='Check/admin';
          break;
        case '6':
           $rec_url='/Admin/Check/manager';
           $url='Check/manager';
          break;
        default:
          # code...
          break;
      }

      $nUserId  = $_POST['user_id'];
      $nCstatus = $_POST['Cstatus'];

      $_tmpUser = $this->getInfo('admin_id,id,user_name','user',['id' => $nUserId]);

      if (session('adminInfo.gpid') == 0)
      {
        $_tmpGroup = $this->getInfo('*','group',['id' => session('adminInfo.gid')]);
      }else{
        $_tmpGroup = $this->getInfo('*','group',['id' => session('adminInfo.gpid')]);
      }

      if($check_status==4){
          M('user')->data(['ability'=>$_POST['ability'],'desire'=>$_POST['desire']])->where('id ='.$_POST['user_id'])->save();
      }

      switch ($nCstatus)
      {
        case 1://通过
          if ($_tmpGroup['name'] == '审核经理')
          {
            $strTitle       = '您的客户【'.$_tmpUser['user_name'].'】已通过审核'.date('Y-m-d h:i:s');
            $strDescription = '您查询的客户【'.$_tmpUser['user_name'].'】，审核经理意见：'.$_POST['opinion'];
            $status_local   = '审核经理审核通过';
              // 消息添加
              $msg = M('message')->
              data(['status_local' => $status_local,'admin_id' => $_tmpUser['admin_id'],'operator_id' => session('adminInfo.id'),'user_id' => $nUserId,'title' => $strTitle,'description' => $strDescription.$status_local,'create_time' => time()])->
              add();
          }
          break;

        case 11;
            $strTitle       = '您提交的客户【'.$_tmpUser['user_name'].'】被审核待定'.date('Y-m-d h:i:s');
            $strDescription = '您提交的客户【'.$_tmpUser['user_name'].'】，被审核待定，原因：'.$_POST['opinion'];
            $status_local   = '待定';
            // 消息添加
            $msg = M('message')->
            data(['status_local' => $status_local,'admin_id' => $_tmpUser['admin_id'],'operator_id' => session('adminInfo.id'),'user_id' => $nUserId,'title' => $strTitle,'description' => $strDescription.$status_local,'create_time' => time()])->
            add();
          break;

        case 12;
            $strTitle       = '您提交的客户【'.$_tmpUser['user_name'].'】被审核退回'.date('Y-m-d h:i:s');
            $strDescription = '您提交的客户【'.$_tmpUser['user_name'].'】，被审核退回，原因：'.$_POST['opinion'];
            $status_local   = '退回';
            // 消息添加
            $msg = M('message')->
            data(['status_local' => $status_local,'admin_id' => $_tmpUser['admin_id'],'operator_id' => session('adminInfo.id'),'user_id' => $nUserId,'title' => $strTitle,'description' => $strDescription.$status_local,'create_time' => time()])->
            add();
          break;

        case 0;
            $strTitle       = '您提交的客户【'.$_tmpUser['user_name'].'】被审核拒绝'.date('Y-m-d h:i:s');
            $strDescription = '您提交的客户【'.$_tmpUser['user_name'].'】，被审核拒绝，原因：'.$_POST['opinion'];
            $status_local   = implode(',', $_POST['reType']);
            // 消息添加
            $msg = M('message')->
            data(['status_local' => $status_local,'admin_id' => $_tmpUser['admin_id'],'operator_id' => session('adminInfo.id'),'user_id' => $nUserId,'title' => $strTitle,'description' => $strDescription.$status_local,'create_time' => time()])->
            add();
          break;
      }



     if($data['status']==1)
     {
        //审核完成，改变状态
              if($check_status==6)
              {
                $check_data=array('update_time'=>time(),'check_status'=>$check_status,'status'=>1);
              }elseif ($check_status==3) {
                $change=$this->change_check($_POST['user_id']);
                $check_data=array('update_time'=>time(),'check_status'=>$check_status,'status'=>1,'check_admin_id'=>$change);
              }
              else{
                $check_data=array('update_time'=>time(),'check_status'=>$check_status,'status'=>1);
              }

              $check=M('user')->where('id='.$_POST['user_id'])->save($check_data);
              redirect($rec_url);
      }else if($data['status']==0)
      {
         $check_data=array('update_time'=>time(),'check_status'=>-1,'status'=>5);
         $check_status=M('user')->where('id='.$_POST['user_id'])->save($check_data);
         $log_status=$this->set_check_log($_POST['user_id']);
         $this->error('审核拒贷',U($url),0);
      }else if($data['status']==11)
      {
         $check_data=array('update_time'=>time(),'status'=>9);
         $check_status=M('user')->where('id='.$_POST['user_id'])->save($check_data);
         $this->error('审核待定，等待补充资料',U($url),0);
      }else{
         $check_data=array('update_time'=>time(),'status'=>12,'check_status'=>-1);
         $check_status=M('user')->where('id='.$_POST['user_id'])->save($check_data);
         $log_status=$this->set_check_log($_POST['user_id']);
         $this->error('审核退回',U($url),1);
      }
  }

  protected function change_check($user_id)
  {
    $user=$this->getInfo('*','car_info','user_id='.$user_id);
    $real=$user['real_loan_quota'];
    if($real<=100000)
    {
      $where='max_money<100000';
    }elseif($real>150000)
    {
      $where='max_money>150000';
    }else{
      $where='min_money>=100000'.' and max_money<=150000';
    }
//   $list=$this->getList('*','admins',$where,'');
      $Model =  M('admins') ;// 实例化一个model对象 没有对应任何数据表
      $list=$Model->query("select a.id from app_admins a left join app_user b on a.id=b.check_admin_id where  $where and gid=10 group by a.id order by count(b.id)  limit 1");
//      print($list);die;
//   foreach ($list as $key => $value) {
//     $list[$key]['count']=M('user')->where('check_admin_id='.$value['id'])->count();
     // $shopids = $shopids.$v['shop_id'].",";
//   }
//     $shopids = substr($shopids,0,strlen($shopids)-1);
//   $rand_keys = array_rand($list);
//   $change=$list[$rand_keys]['id'];
   return $list[0]['id'];
   // print_r($change);
   // exit;
  }

 //财务助理(垫款审核列表)
 public function MatApply()
 {
    $advance=new MatApplyController();
    $list=$advance->getMatApply_status(1);
    $this->assign('list',$list);
    $this->display();
 }

 //财务助理（垫资打款/放贷）
public function payMoney_index()
{
      $where = '1 = 1';
      if(I('get.aid', -1, 'intval') <> -1)
      {
        if(I('get.aid', -1, 'intval')==0)
        {
          $where .=' and  u.aid =0';
        }else{
          $where .=' and aid='.I('get.aid', 0, 'intval');
        }
      }
      $where .= I('get.user_name') != '' ? ' and u.user_name like "%'.I('get.user_name').'%"' : '';

      $where .= I('get.telephone') != '' ? ' and u.telephone = '.I('get.telephone') : '';

      $where .= I('get.create_time_beg') != '' ? ' and u.create_time >= '.strtotime(I('get.create_time_beg')) : '';

      $where .= I('get.create_time_end') != '' ? ' and u.create_time < '.strtotime(I('get.create_time_end')) : '';

//      $where .= I('get.status') = 0 ? ' and m.status=2' : '';
//      $where .= I('get.status') = 1 ? ' and m.pay_type=0 and m.status>3' : '';
      //$where.=' and u.id=m.user_id and u.check_status=6 and (m.status=1 or m.status=2)';
      $where.=' and m.status>=2 and m.pay_type=0 and u.status!=101';

      $list=$this->getList('m.id as mat_id,m.bank_card,m.bank_name,m.pay_id,m.add_time,m.status as mat_status,u.*,b.bank_short_name','user u',$where,'id desc',true,'join app_advance m on u.id=m.user_id left join  app_bank b on u.loan_bank_id=b.id');

      foreach ($list as $key => $value) {
        $group=$this->getInfo('*','group','id='.$value['gpid']);
        $list[$key]['group_npayMoney_indexame']=$group['name'];
      }
    $this->assign('list',$list);
    $this->display();

 }
 //财务助理(垫资审核列表)
 public function MatApply_check()
 {
  if(IS_POST)
  {
      $admin_id = session('adminInfo.id');
      $info     = $this->getInfo('a.*,g.name as group_name',array('admins a','group g'),'a.gid=g.id and a.id='.$admin_id);
      $type     = $info['group_name'];
      $data     = array(
               'user_id'      => $_POST['user_id'],//申请人id
               'admin_id'     => $admin_id,//审核人id
               'admin_name'   => $info['name'],//审核人
               'type'         => $type,//身份类型
               'status'       => $_POST['Cstatus'],//审核：1通过，0不通过
               'note'         => '垫款单信息已录入',
               'opinion'      => $_POST['opinion'],//审核意见
               'add_time'     => time(),
               'check_status' => 8
        );
      $result     = M('check_log')->add($data);
      $check_data = M('user')->where('id='.$_POST['user_id'])->setField('update_time',time());
      $apply      = array('check_admin_id'=>session('adminInfo.id'),'status'=>1);
      $check      = M('advance')->where('user_id='.$_POST['user_id'])->save(['status'=> 2,'update_time'=>time()]);
      M('user')->where('id='.$_POST['user_id'])->save($apply);
      if($check)
      {
          redirect('/Admin/Check/MatApply');
          $this->success('垫款单信息已录入',U('Check/MatApply'));
      }
    }else{
          $id = I('get.user_id',0,'intval');
          $detail = new ApplyController();
          $detail->get_info($id);
          $matInfo=$this->getInfo('a.*,b.name as pay_name',array('advance a','payee b'),'a.pay_id=b.id and a.user_id='.$id);
          $this->assign('matInfo',$matInfo);
          $check_log = $this->getList('*','check_log','user_id='.$id.' and update_status=1','id asc');
          $userFiles = $this->getList('*','user_file','user_id = '.$id,'');
          $this->assign('check_log',$check_log);
          $this->assign('userFiles',$userFiles);
          $this->display();
      }
 }


    //财务打款
    public function pay_money()
    {
        if (IS_POST) {
            $user_id = I('get.user_id', 0, 'intval');
            if ($_POST['type'] == 0) {
                $info = $this->getInfo('*', 'user', 'id=' . $user_id);
                if ($info['check_status'] >= 9) {
                    M('user')->where('id=' . $user_id)->setField('status', 10);
                    $this->error('垫资已打款', U('Check/payMoney_index'), 0);
                } else {
                    $data = array('pay_bank' => $_POST['pay_bank'], 'pay_card' => $_POST['pay_card'], 'advance_money' => $_POST['advance_money'], 'advance_time' => strtotime($_POST['advance_time']), 'update_time' => time(), 'status' => 3);

                    $pay = M('advance')->where('user_id=' . $user_id)->save($data);
                    $log = array('user_id' => $user_id, 'admin_id' => session('adminInfo.id'), 'admin_name' => session('adminInfo.name'), 'type' => session('adminInfo.group_name'), 'status' => 3, 'opinion' => '垫资已打款', 'note' => '垫资已打款', 'add_time' => time(), 'check_status' => 9);
                    M('check_log')->add($log);
                    $user = array('update_time' => time(), 'check_status' => 9);
                    $check_data = M('user')->where('id=' . $user_id)->save($user);
                    $msg = M('message')->
                    data(['status_local' => '垫资已成功打款', 'admin_id' => $info['admin_id'], 'operator_id' => session('adminInfo.id'), 'user_id' => $user_id, 'title' => '您提交的客户【' . $info['user_name'] . '】已打款' . date('Y-m-d h:i:s'), 'description' => '您提交的客户【' . $info['user_name'] . '】已打款', 'create_time' => time()])->
                    add();
                }

            } else {
                $lend = array('lending_money' => $_POST['lending_money'], 'lending_time' => strtotime($_POST['lending_time']), 'update_time' => time(), 'pay_type' => 1);

                $pay = M('advance')->where('user_id=' . $user_id)->save($lend);
                $log = array('user_id' => $user_id, 'admin_id' => session('adminInfo.id'), 'admin_name' => session('adminInfo.name'), 'type' => session('adminInfo.group_name'), 'opinion' => '已放贷', 'note' => '已放贷', 'add_time' => time());
                M('check_log')->add($log);
                $user = array('update_time' => time());
                $check_data = M('user')->where('id=' . $user_id)->save($user);
            }


            if ($pay) {
                $this->success('操作成功', U('Check/payMoney_index'), 0);
            } else {
                $this->error('操作失败', U('Check/payMoney_index'), 0);
            }
        } else {
            $id = I('get.user_id', 0, 'intval');
            $userFiles = $this->getList('*', 'user_file', 'user_id = ' . $id, '');
            $detail = new ApplyController();
            $detail->get_info($id);
            $matInfo = $this->getInfo('a.*,b.name as pay_name', array('advance a', 'payee b'), 'a.pay_id=b.id and a.user_id=' . $id);
            $matInfo['advance_money'] = $detail->carInfo['real_loan_quota'] * (1 + $detail->carInfo['car_dealer'] / 100 + $detail->carInfo['person'] / 100 + $detail->carInfo['car_dealer_commission'] / 100) - $detail->advanceInfo['total_fee'];
            $this->assign('matInfo', $matInfo);

            $this->assign('userFiles', $userFiles);
            $this->display('MatApply_check');
        }
    }
 //财务助理(结清审核)
 public function settle()
 {
  $this->display();
 }

 //审核资料
 public function data()
 {
  $list=$this->getList('u.*,e.status,b.bank_short_name','user u','e.status=2','','','left join app_express e on u.id=e.user_id left join app_bank b on u.loan_bank_id=b.id');
  $this->assign('list',$list);
  $this->display();
 }

 public function data_check()
 {
      if(IS_POST)
      {
         $user_id=$_POST['user_id'];
         $ziliao=$this->getInfo('*','data_check','user_id='.$user_id.' and status=2');
         if($ziliao)
         {
           $this->error('资料已审核完成',U('Check/data'),1);
         }
         $_POST['user_id']=$user_id;
         $_POST['add_time']=time();
         $_POST['update_time']=time();
         $_POST['admin_id']=session('adminInfo.id');
         if($_POST['type']==0)
         {
           $_POST['status']=2;
           M('express')->where('user_id='.$user_id)->setField('status',10);
           $user_info=$this->getInfo('*','user','id='.$user_id);
            if($user_info['check_status']>=6)
            {
                    $status=10;
            }else{
                    $status= 2;
            }
            $user=array('update_time'=>time(),'status'=>$status);
            $check_status=M('user')->where('id='.$user_id)->save($user);
           $log=array('user_id'=>$user_id,'admin_id'=>session('adminInfo.id'),'admin_name'=>session('adminInfo.name'),'type'=>session('adminInfo.group_name'),'opinion'=>'市场部已审核','note'=>'市场部已审核','add_time'=>time(),'status'=>101);

         }else{
           $_POST['status']=1;
           $user=array('status'=>9,'update_time'=>time());
           $check_status=M('user')->where('id='.$user_id)->save($user);
           $log=array('user_id'=>$user_id,'admin_id'=>session('adminInfo.id'),'admin_name'=>session('adminInfo.name'),'type'=>session('adminInfo.group_name'),'opinion'=>'查收资料待定(市场部)','note'=>'查收资料待定（市场部）','add_time'=>time(),'status'=>11);

         }
         M('check_log')->add($log);

         $dataInfo=$this->getInfo('*','data_check','user_id='.$user_id);
         if($dataInfo)
         {
              $result=M('data_check')->where('user_id='.$user_id)->save($_POST);
          }else{
              $result=M('data_check')->add($_POST);
          }
        if($result)
        {
             redirect('/Admin/check/data');
           }else{
             $this->error('审核失败',U('ChaoDan/Confirm'),0);
           }

    }else{
        $id=I('get.user_id',0,'intval');
        $detail=new ApplyController();
        $detail->get_info($id);
        $express=$this->getInfo('*','express','user_id='.$id);
        $dataInfo=$this->getInfo('*','data_check','user_id='.$id);
        $userFiles = $this->getList('*','user_file','user_id = '.$id,'');
        $this->assign('dataInfo',$dataInfo);
        $this->assign('userFiles',$userFiles);
        $this->assign('express',$express);
        $this->display();
    }
 }

   //退回修改check_log表
   public function set_check_log($user_id)
   {
     $result=M('check_log')->where('user_id='.$user_id)->setField('update_status',0);
     if($result)
     {
        return true;
     }else{
        return false;
     }
   }

   public function find_status($user_id,$check_status)
   {
      $info=$this->getInfo('*','user','id='.$user_id.' and (check_status='.$check_status.' or status=9 or status=5)');
      if($info)
      {
        return true;
      }else{
        return false;
      }
   }

    public function length_Phone(){
        $this->display('');
    }

    public function Mat_batch()
    {
        $id=explode(',',$_POST['ids']);
//        print_r($id);die;
//        $status=$_POST['status'];
        foreach ($id as $v) {
            if($v!=0)
            {
                $info=$this->getInfo('*','advance','user_id='.$v);
//                print_r($info);die;
                if($info==null)
                {
                    $this->ajaxReturn(array('info'=>'该操作已不在此状态中','status'=>0));
                    //$this->error('该操作已不在此状态中');
                }
                $data=array('update_time'=>time(),'status'=>2);
                $result=M('advance')->where('user_id='.$v)->save($data);
                M('user')->where('id='.$v)->save(array('check_status'=>8,'update_time'=>time(),'check_admin_id'=>session('adminInfo.id')));
                if($result)
                {
                    $log=array('user_id'=>$v,'admin_id'=>session('adminInfo.id'),'admin_name'=>session('adminInfo.name'),'type'=>session('adminInfo.group_name'),'status'=>6,'opinion'=>'打款审核通过','note'=>'打款审核通过','add_time'=>time(),'check_status'=>8);
                    M('check_log')->add($log);
                }else{
                    $this->ajaxReturn(array('info'=>'操作失败','status'=>0));
                    // $this->error('操作失败',0);
                }
            }

        }
        $this->ajaxReturn(array('info'=>'批量操作成功','status'=>1));
        // $this->success("批量操作成功");
    }


}